import 'package:pointycastle/asymmetric/api.dart';
import 'package:encrypt/encrypt.dart';


class EncryptUtil {

  static Future<String> getRSAString (String plainText,String pubKey) async {
    //final publicKey1 = await parseKeyFromFile<RSAPublicKey>('test/public.pem');
    String publicKey = '''
-----BEGIN PUBLIC KEY-----
$pubKey
-----END PUBLIC KEY-----
''';
    final parser = RSAKeyParser();
    var pubParse =  parser.parse(publicKey) as RSAPublicKey;
    final encrypter = Encrypter(RSA(publicKey: pubParse));
    //开始加密
    final encrypted = encrypter.encrypt(plainText);
    String str = encrypted.base64;//加密后内容可以在线解析或者自行解析
    print("RSA加密===:"+str);
    return str;
  }

}